package com.xiaoxin.experience.common;

import lombok.Getter;
import lombok.Setter;

/**
 * @author xiaoxin
 */
@Setter
@Getter
public class RestResponse<T>
{
    private int resultCode;

    private String resultDesc;

    private T data;

    public RestResponse(int resultCode,String resultDesc,T data)
    {
        this.resultCode = resultCode;
        this.resultDesc = resultDesc;
        this.data = data;
    }

    public static <T> RestResponse<T> success()
    {
        return new RestResponse<>(0,"SUCCESS",null);
    }

    public static <T> RestResponse<T> success(T data)
    {
        return new RestResponse<>(0,"SUCCESS",data);
    }

    public static RestResponse<Void> fail(int resultCode,String resultDesc)
    {
        return new RestResponse<>(resultCode,resultDesc,null);
    }

    public static <T> RestResponse<T> fail()
    {
        return new RestResponse<>(-1,"FAIL",null);
    }

    public static <T> RestResponse<T> fail(String resultDesc)
    {
        return new RestResponse<>(-1,resultDesc,null);
    }
}
